<!doctype html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-model="http://www.w3.org/1999/xhtml" xmlns:v-demo="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .router-link-active {
            color:#f00;
        }
        pre {
            font-family: sans-serif;
            font-size: 1em;
            line-height:1.5em;
        }

    </style>
</head>
<body>

    <div id="app">
        <ul style="position: fixed;left:100px;top:0;">
            <li><router-link to="/">Home</router-link></li>
            <li><router-link to="/posts">Posts</router-link></li>
        </ul>

        <router-view></router-view>
    </div>
</body>

<script src="../../../vender/vue@2.4.2.js"></script>
<script src="../../../vender/vue-router@2.7.0.js"></script>

<script>
    const Home={template:'<div style="height: 3500px;"><h2>Home</h2></div>'};
    const Posts={template:'<div style="height: 3000px;"><h2>Posts</h2></div>'};

    const router=new VueRouter({
        routes:[
            {path:'',component:Home},
            {path:'/posts',component:Posts}
        ],
        scrollBehavior(to,from,savedPosition){
            console.log('savedPosition:',savedPosition);
            if(savedPosition)return savedPosition;
            console.log(0);
            return {x:0,y:0};
        }
    });

    const app=new Vue({
        el:'#app',
        router
    });

</script>
</html>